1 // Fig. 18.8: fig18_08.cpp 2 // An example of a union 3 #include 4 5 union Number { 6 int x; 7 float y; 8 }; 9 10 int main() 11 { 12 Number value; 13 14 value.x = 100; 15 cout << "Put a value in the integer member\n" 16 << "and print both members.\nint: " 17 << value.x << "\nfloat: " << value.y << "\n\n"; 18 19 value.y = 100.0; 20 cout << "Put a value in the floating member\n" 21 << "and print both members.\nint: " 22 << value.x << "\nfloat: " << value.y << endl; 23 return 0; 24 }